package com.du.stutestsys.controller.Administrator;

import com.du.stutestsys.controller.BaseControler;
import com.du.stutestsys.entity.Grade;
import com.du.stutestsys.service.Administrator.GradeService;
import com.du.stutestsys.util.PageUtil;
import com.du.stutestsys.util.DuUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//年级管理
@Controller
public class GradeController extends BaseControler {
    @Autowired
    GradeService gradeService;


    @PostMapping("admin/addGrade")
    public String addGrade(@RequestBody Grade grade,@RequestParam String[] subject_ids){
        boolean b = gradeService.addGradeAndSubject(grade,subject_ids);
        return DuUtil.success(b).toJSONString();
    }

    @PostMapping("admin/updateGrade")
    public String updateGrade(@RequestBody(required = false) Grade grade){
        return DuUtil.success(gradeService.updateGrade(grade)).toJSONString();
    }

    @GetMapping("admin/selectGrade")
    public String selectGrade(@RequestBody(required = false) Grade grade){
        PageUtil pageUtil = DuUtil.setPageUtil(grade,0,10);
        List<Grade> gradeList = gradeService.selectGrade(grade, pageUtil);
        return DuUtil.success(gradeList.size()>0,gradeList,gradeList+"",pageUtil).toJSONString();
    }
}
